package cn.iocoder.yudao.module.wine.dal.mysql.supplyorderitem;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.MPJLambdaWrapperX;
import cn.iocoder.yudao.module.wine.controller.app.supplyorderitem.vo.AppSupplyOrderItemRespVO;
import cn.iocoder.yudao.module.wine.dal.dataobject.supplyinfo.SupplyInfoDO;
import cn.iocoder.yudao.module.wine.dal.dataobject.supplyorderitem.SupplyOrderItemDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.wine.controller.admin.supplyorderitem.vo.*;

/**
 * 订单项信息 Mapper
 *
 * @author 管理员
 */
@Mapper
public interface SupplyOrderItemMapper extends BaseMapperX<SupplyOrderItemDO> {

    default PageResult<SupplyOrderItemDO> selectPage(SupplyOrderItemPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<SupplyOrderItemDO>()
                .eqIfPresent(SupplyOrderItemDO::getOrderId, reqVO.getOrderId())
                .eqIfPresent(SupplyOrderItemDO::getInfoId, reqVO.getInfoId())
                .eqIfPresent(SupplyOrderItemDO::getQuantity, reqVO.getQuantity())
                .eqIfPresent(SupplyOrderItemDO::getPackages, reqVO.getPackages())
                .eqIfPresent(SupplyOrderItemDO::getSalePrice, reqVO.getSalePrice())
                .eqIfPresent(SupplyOrderItemDO::getPayPrice, reqVO.getPayPrice())
                .eqIfPresent(SupplyOrderItemDO::getPremiumPrice, reqVO.getPremiumPrice())
                .betweenIfPresent(SupplyOrderItemDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(SupplyOrderItemDO::getId));
    }

    /**
     *
     * @param orderId
     * @return
     */
    default List<SupplyOrderItemRespVO> getAdminSupplyOrderItemList(Long orderId){
        return selectJoinList(SupplyOrderItemRespVO.class, new MPJLambdaWrapperX<SupplyOrderItemDO>()
                .eqIfPresent(SupplyOrderItemDO::getOrderId, orderId)
                .leftJoin(SupplyInfoDO.class, SupplyInfoDO::getId, SupplyOrderItemDO::getInfoId)
                .selectAll(SupplyOrderItemDO.class)
                .selectAs(SupplyInfoDO::getShowYear, SupplyOrderItemRespVO::getShowYear)
                .selectAs(SupplyInfoDO::getPacking,SupplyOrderItemRespVO::getPacking)
                .selectAs(SupplyInfoDO::getInfoTitle,SupplyOrderItemRespVO::getInfoTitle)
                .selectAs(SupplyInfoDO::getInfoName,SupplyOrderItemRespVO::getInfoName)
                .selectAs(SupplyInfoDO::getFragranceType, SupplyOrderItemRespVO::getFragranceType)
                .selectAs(SupplyInfoDO::getDegree,SupplyOrderItemRespVO::getDegree)
                .selectAs(SupplyInfoDO::getCapacity,SupplyOrderItemRespVO::getCapacity)
                .selectAs(SupplyInfoDO::getProductArea,SupplyOrderItemRespVO::getProductArea)
                .selectAs(SupplyInfoDO::getLanguage,SupplyOrderItemRespVO::getLanguage)
                .selectAs(SupplyInfoDO::getUnit,SupplyOrderItemRespVO::getUnit)
                .orderByDesc(SupplyOrderItemDO::getId));


    }

    default List<AppSupplyOrderItemRespVO> getSupplyOrderItemList(Long orderId){
        return selectJoinList(AppSupplyOrderItemRespVO.class, new MPJLambdaWrapperX<SupplyOrderItemDO>()
                .eqIfPresent(SupplyOrderItemDO::getOrderId, orderId)
                .orderByDesc(SupplyOrderItemDO::getId));
    }

    default List<SupplyOrderItemDO> getSupplyOrderItemListByOrderId(Long id){
        return selectList(new MPJLambdaWrapperX<SupplyOrderItemDO>()
                .eqIfPresent(SupplyOrderItemDO::getOrderId, id));
    }
}
